window.onload = function()
{    
    function onReady()
    {
        var buttonGet   = dojo.byId("get"),
            divMain     = dojo.byId("main");
        var sock = null
        
        function connect()
        {
            sock = new io.Socket(window.location.hostname, {port: 8001, rememberTransport: false});
        
            divMain.innerHTML += '<p>Connecting ...</p>';
            
            sock.connect()
            
            sock.on('connect',
                    function()
                    {
                      divMain.innerHTML += '<p>Connected</p>';
                    }
            );
            
            sock.on('message',
                    function(data)
                    {
                      divMain.innerHTML += '<p>Received: ' + data +'</p>';
                    }
            );
            
            sock.on('disconnect',
                    function(data)
                    {
                      divMain.innerHTML += '<p>disconnect!!! Received: ' + data +'</p>';
                      sock = null;
                    }
            );
        }
        
        function disconnect()
        {
            if (sock != null)
            {
                divMain.innerHTML += '<p>Disconnecting...</p>';
                sock.disconnect();
                sock = null;
            }
        }
        
        connect();
       
        dojo.connect(buttonGet,
                    "onclick",
                    function(evt)
                    {
                       sock.send('get all data');
                    }
        );
    }  
    dojo.ready(onReady);  
}
